package com.digiwin.muke;

import org.apache.flink.api.java.ExecutionEnvironment;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author yanggld
 * @Date 2021/04/25-16:14
 */
public class DataSetDataSourceApp {
    public static void main(String[] args) throws Exception {
        ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
        fromCollection(env);
        textFile(env);
    }

    // 从集合获取数据
    public static void fromCollection(ExecutionEnvironment env ) throws Exception {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add(i);
        }
        env.fromCollection(list).print();
    }

    // 从文件获取数据
    public static void textFile(ExecutionEnvironment env) throws Exception {
        String filePath = "D:\\develop\\java\\IdeaProjects\\flink-java\\src\\main\\resources\\hello.txt";
        env.readTextFile(filePath).print();
        System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
        filePath = "D:\\develop\\java\\IdeaProjects\\flink-java\\src\\main\\resources";
        env.readTextFile(filePath).print();
    }
}
